<?php

namespace app\dev\controller;

use think\Controller;
use app\common\model\User;
use app\common\model\com\Info as ComModel;

/**
 * 模拟程序
 */
class Moni extends Controller{

    
    /**
     * 模拟添加企业
     */
    public function addCom($num = 2000){

        $success = 0;
        
        for ($i = 2000; $i < $num; $i++) {

            $res = ComModel::create([
                'name' => 'moniQY'.date('YmdHi').$i,
                'short_name'  => 'moniQY'.$i,
                'user_id'  => 0,
                'credit_no'  => '',
                'estate_info_id'  => mt_rand(1,5),
                'cate_ids'  => mt_rand(630,780),
                'com_size_id'  => mt_rand(614,620),
                'status'  => '1',
                'server_date'  => mt_rand(1,31),
            ]);

            if($res){
                $success ++;
            }
        }

        return $success;
    }

    /**
     * 模拟添加人数
     */
    public function addUser($num = 220000){

        $conf = config("userattr");

        $success = 0;

        $job_ids = \app\common\model\job\Cate::where('pid','>',0)->where('show_asint',1)->column('id');
        $int_ids = \app\common\model\Category::where('type','int_cate_new')->where('pid','>',0)->column('id');

        for ($i = 6834; $i < $num; $i++) {
            $age = array_rand($conf['age'], 1);
            $gender = array_rand($conf['gender'], 1);
            $edu = array_rand($conf['edu'], 1);
            $emo = array_rand($conf['emo'], 1);
            $job = array_rand($job_ids, 1);
            

            $user = User::create([
                'nickname' => 'moni'.date('YmdHi').$i,
                'avatar'  => '',
                'birthday'  => $conf['age'][$age]['value'],
                'gender'  => $conf['gender'][$gender]['value'],
                'job_id'  => $job_ids[$job],
                'edu'  => $conf['edu'][$edu]['value'],
                'emo'  => $conf['emo'][$emo]['value'],
                'com_info_id'  => mt_rand(17,22100),
                'server_date' => mt_rand(1,31),
            ]);

            if($user){
                $success++;
            }else{
                continue;
            }

            #随机生成兴趣
            $ints = array_rand($int_ids, mt_rand(15,35));
            $itds = [];
            foreach ($ints as $key => $index) {
                $itds[] = $int_ids[$index];
            }
            \app\common\model\question\Qa::create([
                'question_id' => 11,
                'user_id' => $user->id,
                'qa_list_id' => INTREST_INT,
                'answer_ids' => implode(",", $itds),
                'status' => 1,
            ]);

        }

        return $success;
    }

}